package com.qyhl.webtv.module_user.shop.item;

import android.content.Context;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.makeramen.roundedimageview.RoundedImageView;
import com.qyhl.webtv.basiclib.utils.DateUtils;
import com.qyhl.webtv.basiclib.utils.StringUtils;
import com.qyhl.webtv.commonlib.entity.user.ShoppingOrderBean;
import com.qyhl.webtv.module_user.R;
import com.zhy.adapter.recyclerview.base.ItemViewDelegate;
import com.zhy.adapter.recyclerview.base.ViewHolder;

public class ItemShopOrderTwo implements ItemViewDelegate<ShoppingOrderBean> {
    private Context mContext;

    public ItemShopOrderTwo(Context mContext) {
        this.mContext = mContext;
    }

    @Override
    public int getItemViewLayoutId() {
        return R.layout.login_item_shop_order_two;
    }

    @Override
    public boolean isForViewType(ShoppingOrderBean item, int position) {
        return item.getItem().getItemType() == 1;
    }

    @Override
    public void convert(ViewHolder holder, ShoppingOrderBean bean, int position) {
        if (bean.getOrderStatus().equals("NOT_CHECKED")) {
            if (StringUtils.isEmpty(bean.getItem().getExchangeDeadline()) || DateUtils.isBeforeTime(bean.getItem().getExchangeDeadline())) {
                holder.setText(R.id.status, "待兑换");
                holder.setText(R.id.status_two, "待兑换");
            }else{
                holder.setText(R.id.status, "已过期");
                holder.setText(R.id.status_two, "已过期");
            }
        } else {
            holder.setText(R.id.status, "已兑换");
            holder.setText(R.id.status_two, "已兑换");
        }

        holder.setText(R.id.shop_name, bean.getShop().getName());

        holder.setText(R.id.address, "店铺地址:" + bean.getShop().getAddress());

        holder.setText(R.id.orderId, "订单编号:" + bean.getId());

        RoundedImageView cover = holder.getView(R.id.cover);

        Glide.with(mContext)
                .load(bean.getItemPic())
                .apply(new RequestOptions().error(R.drawable.cover_normal_default).placeholder(R.drawable.cover_normal_default))
                .into(cover);

        holder.setText(R.id.title, bean.getItemName());

        holder.setText(R.id.number, "x" + bean.getItemNumber());

        holder.setText(R.id.score, bean.getItemPrice());

        holder.setText(R.id.deadline, StringUtils.isNotEmpty(bean.getItem().getExchangeDeadline()) ? DateUtils.translateToShopping(bean.getItem().getExchangeDeadline()) : "不限期");
    }
}
